package com.zznode.client.wlanpolling.model;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class SystemSettingManager {
	private Context context;
	
	public SystemSettingManager(Context context) {
		this.context = context;
	}
	
	public void saveSystemSetting(SystemSetting setting) {
		SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		
		Editor editor = mPrefs.edit();
		
		editor.putString("pingParams", setting.getPingParams());
		editor.putString("adslServerAdress", setting.getAdslServerAdress());
		editor.putString("uploadFileUrl", setting.getUploadFileUrl());
		editor.putInt("ftpTestCount", setting.getFtpTestCount());
		editor.putInt("relateTestTimes", setting.getRelateTestTimes());
		editor.putInt("webAuthTimes", setting.getWebAuthTimes());
		editor.putInt("reassociateTimeout", setting.getReassociateTimeout());
		editor.putString("apPingParams", setting.getApPingParams());

		
		editor.commit();
	}
	
	public SystemSetting getSystemSetting() {
		
		SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		
		SystemSetting setting = new SystemSetting();
		
		setting.setPingParams(mPrefs.getString("pingParams", " -c 50 -s 64"));
		setting.setApPingParams(mPrefs.getString("apPingParams", " -c 300 -s 64"));
		setting.setAdslServerAdress(mPrefs.getString("adslServerAdress", "61.191.20.30"));
		setting.setUploadFileUrl(mPrefs.getString("uploadFileUrl", ""));
		setting.setFtpTestCount(mPrefs.getInt("ftpTestCount", 5));
		setting.setRelateTestTimes(mPrefs.getInt("relateTestTimes", 50));
		setting.setWebAuthTimes(mPrefs.getInt("webAuthTimes", 1));
		setting.setReassociateTimeout(mPrefs.getInt("reassociateTimeout", 90));
		
		return setting;
	}
}
